# -*- coding: utf-8 -*-
from django.db import models
from django.contrib.auth.models import AbstractUser


class User(AbstractUser):
    username = models.CharField('用户名',max_length=64,unique=True)
    password = models.CharField('密码', max_length=128)
    mobile = models.CharField('手机号',max_length=20,null=True,blank=True)
    email = models.EmailField('邮箱', null=True,blank=True)

    class Meta:
        db_table = 'tb_user'


class Role(models.Model):
    name = models.CharField('角色名',max_length=32)
    zh_name = models.CharField("中文名称",max_length=64)
    description = models.CharField('角色描述',max_length=264, null=True, blank=True)

    class Meta:
        db_table = 'tb_role'

    def __str__(self):
        return self.name


class UserRole(models.Model):
    user = models.ForeignKey(User,on_delete=models.CASCADE)
    role = models.ForeignKey(Role, on_delete=models.CASCADE)

    class Meta:
        db_table = 'tb_userrole'

    def __str__(self):
        return '%s-%s'%(self.user.username,self.role.name)